//
//  CMMyCreReportCtrl.m
//  CreditManger
//
//  Created by sky on 15/11/2.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMMyCreReportCtrl.h"
#import "CMAnswerCtrl.h"
#import "CMFindReportByUidParam.h"
#import "CMFindReportByUidParser.h"
#import "CMFindReportByUidInfo.h"
#import "CMFindReportByUidItemInfo.h"
#import "CMLoginManager.h"


@interface CMMyCreReportCtrl (){
    UILabel *_name;
    UILabel *_idcard;
    UILabel *_numrep;
    UIView  *_numupdate;
    UILabel *_bankcardnum;
    UILabel *_bankcardoverdue;
    UILabel *_numloan;
    UILabel *_date;
    UILabel *_states;
}


@property (nonatomic , strong)CMFindReportByUidInfo *iteminfo;

@end

@implementation CMMyCreReportCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)buildLayout{
    self.title = @"我的信用报告";
    
    
    
    _numupdate = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 4, 45 + 14, 4, 4)];
    _numupdate.backgroundColor = [LCCommon getColor:@"f75a54"];
    _numupdate.layer.cornerRadius = 2;
    [self.view addSubview:_numupdate];
    
    
    
    UIView *bgview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
    bgview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgview];
    [self makeLinewithRect:CGRectMake(0, 44.5, SCREEN_WIDTH, .5) Color:[LCCommon getColor:@"cccccc"] addview:bgview];
    
    
    
    NSString *str = @"232721********1113";
    CGSize strsize = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
    _idcard = [self LabelWithRect: CGRectMake(SCREEN_WIDTH/2 - strsize.width/2, 0, strsize.width, 45) textColor:[LCCommon getColor:@"333333"] textstr:str textfont:13 textstyle:NSTextAlignmentCenter];
    [bgview addSubview:_idcard];
    
    
    
    _name = [self LabelWithRect:CGRectMake(10, 0,SCREEN_WIDTH - _idcard.origin.x - 10  , 45) textColor:[LCCommon getColor:@"333333"] textstr:@"张三" textfont:15 textstyle:NSTextAlignmentLeft];
    [bgview addSubview:_name];
    
    
    
    UIView *blowview = [[UIView alloc]initWithFrame:CGRectMake(10, 45 + 45, SCREEN_WIDTH - 20, 280/2)];
    blowview.backgroundColor = [UIColor whiteColor];
    blowview.layer.borderColor = [LCCommon getColor:@"cccccc"].CGColor;
    blowview.layer.borderWidth = .5;
    blowview.layer.cornerRadius = 2.5;
    [self.view addSubview:blowview];
    
    
    
    [self makeLinewithRect:CGRectMake(0, 50, blowview.size.width, .5) Color:[LCCommon getColor:@"cccccc"] addview:blowview];
    [self makeLinewithRect:CGRectMake(15, 50 + 45, blowview.size.width - 30, .5) Color:[LCCommon getColor:@"e5e5e5"] addview:blowview];
    
    
    
    _numrep = [self LabelWithRect:CGRectMake(10, 45/2 - 15/2  + 45, SCREEN_WIDTH/2 - 10, 15) textColor:[LCCommon getColor:@"333333"] textstr:@"1 份信用报告" textfont:15 textstyle:NSTextAlignmentLeft];
    [self.view addSubview:_numrep];
    [_numrep setAttributedText:[self MakeWenziStyleWithStr:_numrep.text orign:0 stop:1]];
    
    
    
    UILabel *updata = [self LabelWithRect:CGRectMake(_numupdate.origin.x - 2 - 6 * 15, _numrep.origin.y, 6*15, 15) textColor:[LCCommon getColor:HIGH_COLOR] textstr:@"更新信用报告" textfont:15 textstyle:NSTextAlignmentRight];
    updata.userInteractionEnabled = YES;
    [self.view addSubview:updata];
    
    
    
//    UIImage *shuaxin = [UIImage imageNamed:@"mycenter_update"];
//    UIImageView *upshuju = [[UIImageView alloc]initWithFrame:CGRectMake(updata.origin.x - 5 - shuaxin.size.width, (20 - shuaxin.size.height / 2) + 40, shuaxin.size.width, shuaxin.size.height)];
//    upshuju.image = shuaxin;
//    upshuju.userInteractionEnabled = YES;
//    [self.view addSubview:upshuju];
    
    
    
    UITapGestureRecognizer *reload = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(reloadtap)];
    //UITapGestureRecognizer *reload1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(reloadtap)];
    [updata addGestureRecognizer:reload];
    //[upshuju addGestureRecognizer:reload1];
    
    
    [self makeLinewithRect:CGRectMake(0 , 50/2 - 14/2, 5, 14) Color:[LCCommon getColor:HIGH_COLOR] addview:blowview];
    
    
    _date = [self LabelWithRect:CGRectMake(15, 50/2 - 14/2, SCREEN_WIDTH/2- 15 -10, 14) textColor:[LCCommon getColor:@"333333"] textstr:@"2015-04-08" textfont:14 textstyle:NSTextAlignmentLeft];
    [blowview addSubview:_date];
    
    
    
    UIImage *jiantou = [UIImage imageNamed:@"mycenter_right"];
    UIImageView *jtview = [[UIImageView alloc]initWithFrame:CGRectMake(blowview.size.width - 15 - jiantou.size.width, 50 / 2 - jiantou.size.height/2, jiantou.size.width, jiantou.size.height)];
    jtview.image = jiantou;
    [blowview addSubview:jtview];
    
    
    [blowview addSubview: [self LabelWithRect:CGRectMake(jtview.origin.x - 5 - 6 * 14, _date.origin.y, 6 * 14, 14) textColor:[LCCommon getColor:@"333333"] textstr:@"查看报告详情" textfont:14 textstyle:NSTextAlignmentRight]];
    
    
    
    _bankcardnum = [self LabelWithRect:CGRectMake(15, (45/2 - 14/2) + 50 , blowview.size.width/2 - 15, 14) textColor:[LCCommon getColor:@"333333"] textstr:@"信用卡 7 张" textfont:14 textstyle:NSTextAlignmentLeft];
    [_bankcardnum setAttributedText:[self MakeWenziStyleWithStr:_bankcardnum.text orign:4 stop:1]];
    [blowview addSubview:_bankcardnum];
    
    
    
    _bankcardoverdue = [self LabelWithRect:CGRectMake(blowview.size.width - 12 * 4 - 15, (45/2 - 12/2) + 50, 12 * 4, 12) textColor:[LCCommon getColor:@"f35555"] textstr:@"2张逾期" textfont:12 textstyle:NSTextAlignmentRight];
    [blowview addSubview:_bankcardoverdue];
    
    
    
    UIImage *wrong = [UIImage imageNamed:@"unusua_logo"];
    UIImageView *unsuavi = [[UIImageView alloc]initWithFrame:CGRectMake(_bankcardoverdue.origin.x - wrong.size.width, (45/2 - wrong.size.height/2) + 50, wrong.size.width, wrong.size.height)];
    unsuavi.image = wrong;
    [blowview addSubview:unsuavi];
    
    
    
    _numloan = [self LabelWithRect:CGRectMake(15, (45/2 - 14/2) + 50 + 45, blowview.size.width /2 - 15 , 14) textColor:[LCCommon getColor:@"333333"] textstr:@"贷款 0 笔" textfont:14 textstyle:NSTextAlignmentLeft];
    [_numloan setAttributedText:[self MakeWenziStyleWithStr:_numloan.text orign:3 stop:1]];
    [blowview addSubview:_numloan];
    
    
    
    
    _states =  [self LabelWithRect:CGRectMake(blowview.size.width -  12 * 2 - 15, (45/2 - 12/2) + 50 + 45 , 24, 12) textColor:[LCCommon getColor:@"333333"] textstr:@"正常" textfont:12 textstyle:NSTextAlignmentRight];
    [blowview addSubview:_states];
    
    [self requestForReport];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - reloadtap

-(void)reloadtap{
    LLog(@"reloadtap");
    CMAnswerCtrl *answer = [[CMAnswerCtrl alloc]init];
    [self.navigationController pushViewController:answer animated:YES];
}

#pragma mark - makewenzi

-(NSMutableAttributedString *)MakeWenziStyleWithStr:(NSString *)str orign:(int)x stop:(int)y{
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc]initWithString:str];
    [noteStr addAttribute:NSForegroundColorAttributeName value:[LCCommon getColor:@"33CC99"] range:NSMakeRange(x, y)];
    return noteStr;
}
-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}


-(void)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
}



#pragma mark - RequestForReprt

-(void)requestForReport{
    CMFindReportByUidParam *param = [[CMFindReportByUidParam alloc]init];
    param.uid = [CMLoginManager sharedCMLoginManager].currentUserInfo.uid;
    param.token = [CMLoginManager sharedCMLoginManager].currentUserInfo.token;
    
    CMFindReportByUidParser *parser = [[CMFindReportByUidParser alloc]init];
    [NetCenter getDataFromURL:Method_findReportByUid params:param parser:parser result:^(ParserResult *myResult) {
        if (myResult.code == 0) {
            
            CMFindReportByUidInfo *info = (CMFindReportByUidInfo *)myResult;
            self.iteminfo = info;
            
        }else{
            DISSMISS_ERR(myResult.message);
        }
    } failure:^(NSError *error) {
        DISSMISS_ERR([error description]);
    }];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
